added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSWPFAnimatedImage / MainWindow.xaml.cs
blob16de2e5f9a969f1dae4129426fa9ace0a49d150e
1 /************************************* Module Header **************************************\
2 * Module Name: MainWindow.xaml.cs
3 * Project: CSWPFDataBinding
4 * Copyright (c) Microsoft Corporation.
5 *
6 * The sample demonstrates how to display a series of photos just like a digital
7 * picuture frame with a "Wipe" effect.
8 *
9 *
10 * This source is subject to the Microsoft Public License.
11 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
12 * All other rights reserved.
14 * History:
15 * * 11/23/2009 3:00 PM Linda Liu Created
17 \******************************************************************************************/
19 using System;
20 using System.Collections.Generic;
21 using System.Linq;
22 using System.Text;
23 using System.Windows;
24 using System.Windows.Controls;
25 using System.Windows.Data;
26 using System.Windows.Documents;
27 using System.Windows.Input;
28 using System.Windows.Media;
29 using System.Windows.Media.Imaging;
30 using System.Windows.Navigation;
31 using System.Windows.Shapes;
32 using System.Windows.Media.Animation;
34 namespace CSWPFAnimatedImage
36 /// <summary>
37 /// Interaction logic for Window1.xaml
38 /// </summary>
39 public partial class MainWindow : Window
41 public MainWindow()
43 InitializeComponent();
46 int nextImageIndex;
47 List<BitmapImage> images = new List<BitmapImage>();
49 private void Window_Loaded(object sender, RoutedEventArgs e)
51 // initialize the images collection
52 images.Add(new BitmapImage(new Uri("Images/image1.jpg", UriKind.Relative)));
53 images.Add(new BitmapImage(new Uri("Images/image2.jpg", UriKind.Relative)));
54 images.Add(new BitmapImage(new Uri("Images/image3.jpg", UriKind.Relative)));
55 images.Add(new BitmapImage(new Uri("Images/image4.jpg", UriKind.Relative)));
57 nextImageIndex = 2;
60 private void VisbleToInvisible_Completed(object sender, EventArgs e)
62 // change the source of the myImage1 to the next image to be shown
63 // and increase the nextImageIndex
64 this.myImage1.Source = images[nextImageIndex++];
66 // if the nextImageIndex exceeds the top bound of the ocllection,
67 // get it to 0 so as to show the first image next time
68 if (nextImageIndex == images.Count)
70 nextImageIndex = 0;
73 // get the InvisibleToVisible storyboard and start it
74 Storyboard sb = this.FindResource("InvisibleToVisible") as Storyboard;
75 sb.Begin(this);
79 private void InvisibleToVisible_Completed(object sender, EventArgs e)
81 // change the source of the myImage2 to the next image to be shown
82 // and increase the nextImageIndex
83 this.myImage2.Source = images[nextImageIndex++];
85 // if the nextImageIndex exceeds the top bound of the ocllection,
86 // get it to 0 so as to show the first image next time
87 if (nextImageIndex == images.Count)
89 nextImageIndex = 0;
92 // get the VisibleToInvisible storyboard and start it
93 Storyboard sb = this.FindResource("VisibleToInvisible") as Storyboard;
94 sb.Begin(this);